from flask import Blueprint, request
from static.connect.conn_mysql import Connect
from static.api.access_token import Card
app_get_phone = Blueprint('app_get_phone', __name__)


@app_get_phone.route('/app_get_phone', methods=['POST'])
def get_phone():

    user_id = request.form.get('user_id')
    access_token = request.form.get('access_token')
    print(access_token, user_id)
    with Card() as C:
        verify_result = C.access_tokens(access_token, user_id)

        if verify_result['status'] != 1:
            print(verify_result)

            return verify_result

        else:

            with Connect() as c:

                select_sql = "SELECT * FROM users WHERE user_id=%s"

                result = c.select_one(sql, (user_id,))

            return {
                "status": 1,
                "errorCode": None,
                "errorMsg": None,
                "resultBody": result['user']
            }
